using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace RunAliasCreator
{
	static class Program
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(params string[] arguments)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			string path = null;
			string alias = null;
			GetCommandLineArguments(arguments, out path, out alias);
			Application.Run(new RunAliasForm(path, alias));
		}

		private static void GetCommandLineArguments(string[] arguments, out string path, out string alias)
		{
			path = null;
			alias = null;
			if (arguments == null || arguments.Length == 0) return;
			int pathEndIndex;
			string pathBuffer;
			if (arguments[0].IndexOf(' ') >= 0)
			{
				pathEndIndex = 1;
				pathBuffer = arguments[0];
			}
			else
			{
				pathEndIndex = Math.Max(0, arguments.Length - 2);
				pathBuffer = string.Empty;
				for (int i = 0; i < Math.Max(1, arguments.Length); i++)
				{
					if (i > 0) pathBuffer += " ";
					pathBuffer += arguments[i];
					if (File.Exists(pathBuffer) || Directory.Exists(pathBuffer))
					{
						pathEndIndex = i + 1;
						break;
					}
				}
			}
			path = pathBuffer;
			alias = string.Empty;
			for (int i = pathEndIndex; i < arguments.Length; i++)
			{
				alias += arguments[i];
			}
		}

	}
}